<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Mockery\Exception;

class GamePrizeLog extends Model
{
    public $timestamps = false;
    protected $table = 'base_game_prize_log';

    const STATUS_WAITING = 1;
    const STATUS_SHIPPED = 2;
    const STATUS_COLLECT = 3;
    const STATUS_REFUSE = 4;

    static $StatusDisplay = [
        self::STATUS_WAITING => '待发货',
        self::STATUS_SHIPPED => '已发货',
        self::STATUS_COLLECT => '已收货',
        self::STATUS_REFUSE => '拒绝',
    ];


    #####关联关系
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id', 'c_id');
    }

    public function game()
    {
        return $this->belongsTo(Game::class, 'game_id', 'id');
    }

    public function commodity()
    {
        return $this->belongsTo(GameCommodity::class, 'commodity_id', 'id');
    }

    #####关联关系end


    /**
     * 拒绝
     * @param $gamePrizeLog
     * @param $request
     * @return array
     */
    static function Refuse($gamePrizeLog, $request)
    {
        try {
            $gamePrizeLog->status = self::STATUS_REFUSE;
            $gamePrizeLog->check_content = $request->check_content;
            if (!$gamePrizeLog->save()) {
                return ['status' => 2, 'message' => '失败'];
            }
            return ['status' => 1, 'message' => '成功'];
        } catch (Exception $exception) {
            return ['status' => 2, 'message' => '失败'];
        }
    }


    /**
     * 通过
     * @param $gamePrizeLog
     * @param $request
     * @return array
     */
    static function Agree($gamePrizeLog, $request)
    {
        try {
            $gamePrizeLog->status = self::STATUS_SHIPPED;
            $gamePrizeLog->express_name = $request->express_name;
            $gamePrizeLog->express_order = $request->express_order;
            if (!$gamePrizeLog->save()) {
                return ['status' => 2, 'message' => '失败'];
            }
            return ['status' => 1, 'message' => '成功'];
        } catch (Exception $exception) {
            return ['status' => 2, 'message' => '失败'];
        }
    }
}
